<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>类型判断</title>
</head>

<body>
    <script>
        // typeof() 对基本类型没问题，遇到引用类型就不管用了
        console.log(typeof 666)
        console.log(typeof [1, 2, 3]);

        // instanceof 只能判断引用类型，不能判断基本类型
        console.log([] instanceof Array)
        console.log('abc' instanceof String);

        // constructor 几乎可以判断基本数据类型和引用类型
        console.log(('123').constructor == String);

        // Object.prototype.toString.call()
        var opt = Object.prototype.toString
        console.log(opt.call('123'));
        console.log(opt.call(456));
        console.log(opt.call([1, 2, 3]));
        console.log(opt.call({}));
        console.log(opt.call(true));
        console.log(opt.call(() => {}));
    </script>
</body>

</html>